package org.example.bigwork.service.impl;

import org.example.bigwork.entity.Student;
import org.example.bigwork.mapper.StudentMapper;
import org.example.bigwork.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private StudentMapper studentMapper;

    @Override
    public Student login(Student student) {
        if (student.getStudentId() ==null || student.getPassword() == null){
            throw new RuntimeException("学生ID或密码不能为空");
        }

        Student student1 = studentMapper.findById(student.getStudentId());
        if (student1 == null) {
            throw new RuntimeException("用户不存在");
        }

        if (!student1.getPassword().equals(student.getPassword())){
            throw new RuntimeException("密码错误");
        }
        return student1;
    }
}

